package apiday08.homework;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ReflectDemo4 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("apiday08.homework.Person");
        Object obj = cls.newInstance();
        Method method = cls.getDeclaredMethod("heHe");
        method.setAccessible(true);
        System.out.println(obj);
        method.setAccessible(false);

        Class cls1 = Class.forName("apiday08.homework.Teacher");
        Object obj1 = cls1.newInstance();

        Field field = cls1.getField("name");
        field.set(obj1,"刘伟强");
        System.out.println(obj1);
        System.out.println(field.get(obj1));
    }
}
